/*
							Copyright (C) 2010  Alourien Team
									
						This file is part of the Alourien Engine.

    The Alourien Engine is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The Alourien Engine is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with the Alourien Engine.  If not, see <http://www.gnu.org/licenses/>.
	
 *File Name: Alourien.h
 *Programmer: Manuel Cuellar
 *Date of Last Update: 9/30/2010
 *
 *Purpose: This is our main engine header code. Meaning, it initializes
 * all assets and APIs required(Direct3D, etc.) in the implementation
 *
 *Basic info: PLEASE DO NOT CHANGE ANY CODE HERE WITHOUT PERMISSION AS THIS
 * AFFECTS MOSTLY EVERY OTHER PIECE OF CODE IN THE PROJECT
 *
 *UPDATES:
 *
 *
 *
 */

#ifndef _ALOURIEN_H
#define _ALOURIEN_H 1

#include <iostream>
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <DxErr.h>
#include "COurTimer.h"

#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define REVISION 2

//External variables and functions
extern bool gameover;
extern bool game_preload();
extern bool game_init(HWND);
extern void game_update();
extern void game_end();

namespace Alourien
{
	class Engine
	{
	private:
		int p_versionMajor, p_versionMinor, p_revision;
		HWND p_windowHandle;
		LPDIRECT3D9 p_d3d;
		LPDIRECT3DDEVICE9 p_device;
		LPDIRECT3DSURFACE9 p_backbuffer;
		LPD3DXSPRITE p_sprite_handler;
		std::string p_appTitle;
		bool p_fullscreen;
		int p_screenWidth;
		int p_screenHeight;
		int p_colorDepth;
		bool p_pauseMode;
		D3DCOLOR p_ambientColor;
		bool p_maximizeProcessor;
		COurTimer p_coreTimer;
		long p_frameCount_core;
		long p_frameRate_core;
		COurTimer p_realTimer;
		long p_frameCount_real;
		long p_frameRate_real;

	public:
		Engine();
		virtual ~Engine();
		int Init(int width, int height, int colorDepth, bool fullscreen);
		void Close();
		void Update();
		void message(std::string message, std::string title = "ALOURIEN ENGINE");
		void fatalError(std::string message, std::string title = "FATAL ERROR");
		void Shutdown();
		void ClearScene(D3DCOLOR colorValue);
		void SetDefaultMaterial();
		void SetAmbient(D3DCOLOR colorValue);
		int RenderStart();
		int RenderStop();
		int Release();

		//Accessors and Mutators (get/set functions)
		bool isPaused() { return this->p_pauseMode; }
		void setPaused(bool value) { this->p_pauseMode = value; }
		LPDIRECT3DDEVICE9 getDevice() { return this->p_device; }
		LPDIRECT3DSURFACE9 getBackBuffer() { return this->p_backbuffer; }
		void setWindowHandle(HWND hWnd) { this->p_windowHandle = hWnd; }
		HWND getWindowHandle() { return this->p_windowHandle; }
		std::string getAppTitle() { return this->p_appTitle; }
		void setAppTitle(std::string title) { this->p_appTitle = title; }
		int getVersionMajor() { return this->p_versionMajor; }
		int getVersionMinor() { return this->p_versionMinor; }
		int getRevision() { return this->p_revision; }
		std::string getVersionText();
		long getFrameRate_core() { return this->p_frameRate_core; }
		long getFrameRate_real() { return this->p_frameRate_real; }
		int getScreenWidth() { return this->p_screenWidth; }
		void setScreenWidth(int value) { this->p_screenWidth = value; }
		int getScreenHeight() { return this->p_screenHeight; }
		void setScreenHeight(int value) { this->p_screenHeight = value; }
		int getColorDepth() { return this->p_colorDepth; }
		void setColorDepth(int value) { this->p_colorDepth = value; }
		bool getFullScreen() { return this->p_fullscreen; }
		void setFullScreen(bool value) { this->p_fullscreen = value; }
		bool getMaximizeProcessor() { return this->p_maximizeProcessor; }
		void setMaximizeProcessor(bool value) { this->p_maximizeProcessor = value; }

	}; //Class

}; //Namespace

//Define the global engine object (VISIBLE EVERYWHERE!)
extern Alourien::Engine* g_engine;

#endif